package de.graffiti.services;

import java.util.Properties;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import de.graffiti.interfaces.WallItemService;

/**
 * This is a webservice class exposing a method called greet which takes a input
 * parameter and greets the parameter with hello.
 * 
 * @author dhanago
 */

/*
 * @WebService indicates that this is webservice interface and the name
 * indicates the webservice name.
 */
@WebService(name = "AppletUploadService")
/*
 * @SOAPBinding indicates binding information of soap messages. Here we have
 * document-literal style of webservice and the parameter style is wrapped.
 */
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
public class AppletUploadService
{

	/**
	 * This method takes a input parameter and appends "Hello" to it and returns
	 * the same.
	 * 
	 * @param name
	 * @return
	 */
	@WebMethod
	public String uploadItem(@WebParam(name = "sessionid") String sessionid, @WebParam(name = "wallpaperid") int wallpaperid, @WebParam(name = "author") String author, @WebParam(name = "content") String content, @WebParam(name = "contenttype") String contenttype, @WebParam(name = "height") int height, @WebParam(name = "width") int width, @WebParam(name = "xpos") int xpos, @WebParam(name = "ypos") int ypos)
	{
		Properties p = new Properties();
		p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
		p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
		p.put(Context.PROVIDER_URL, "jnp://localhost:1099");
		Context ctx;
		try
		{
			ctx = new InitialContext(p);

			Object ref = ctx.lookup("WallItemServiceBean/remote");
			WallItemService wallitem = (WallItemService) PortableRemoteObject.narrow(ref, WallItemService.class);
			wallitem.uploadItem(wallpaperid, sessionid, author, content, contenttype, height, width, xpos, ypos);

		} catch (NamingException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "saved";

	}

}